<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.3/css/all.min.css" integrity="sha256-2H3fkXt6FEmrReK448mDVGKb3WW2ZZw35gI7vqHOE4Y=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"example.com","root":"/","images":"/images","scheme":"Pisces","version":"8.6.1","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>
<meta name="description" content="Docker1、安装配置安装源 1yum-config-manager --add-repo https:&#x2F;&#x2F;download.docker.com&#x2F;linux&#x2F;centos&#x2F;docker-ce.repo  查询docker版本信息 1yum list docker-ce --showduplicates | sort -r  安装docker 1yum install docker-ce-17.">
<meta property="og:type" content="article">
<meta property="og:title" content="Docker">
<meta property="og:url" content="http://example.com/2021/07/27/Docker/index.html">
<meta property="og:site_name" content="运维の博客">
<meta property="og:description" content="Docker1、安装配置安装源 1yum-config-manager --add-repo https:&#x2F;&#x2F;download.docker.com&#x2F;linux&#x2F;centos&#x2F;docker-ce.repo  查询docker版本信息 1yum list docker-ce --showduplicates | sort -r  安装docker 1yum install docker-ce-17.">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-07-27T09:45:38.000Z">
<meta property="article:modified_time" content="2021-07-27T09:46:33.607Z">
<meta property="article:author" content="acho ops">
<meta property="article:tag" content="Docker">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="http://example.com/2021/07/27/Docker/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"http://example.com/2021/07/27/Docker/","path":"2021/07/27/Docker/","title":"Docker"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>Docker | 运维の博客</title>
  




  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">运维の博客</h1>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">后浪</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li>
        <li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li>
        <li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li>
        <li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Docker"><span class="nav-number">1.</span> <span class="nav-text">Docker</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1%E3%80%81%E5%AE%89%E8%A3%85"><span class="nav-number">1.1.</span> <span class="nav-text">1、安装</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2%E3%80%81%E9%85%8D%E7%BD%AE"><span class="nav-number">1.2.</span> <span class="nav-text">2、配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3%E3%80%81%E9%95%9C%E5%83%8F"><span class="nav-number">1.3.</span> <span class="nav-text">3、镜像</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4%E3%80%81%E5%AE%9A%E5%88%B6%E9%95%9C%E5%83%8F"><span class="nav-number">1.4.</span> <span class="nav-text">4、定制镜像</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5%E3%80%81%E9%95%9C%E5%83%8F%E5%B1%82%E6%95%B0"><span class="nav-number">1.5.</span> <span class="nav-text">5、镜像层数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6%E3%80%81DockerFile"><span class="nav-number">1.6.</span> <span class="nav-text">6、DockerFile</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-overview">
            <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">acho ops</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">9</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">9</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">10</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



          </div>
        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/07/27/Docker/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="acho ops">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="运维の博客">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Docker
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>
      

      <time title="创建时间：2021-07-27 17:45:38 / 修改时间：17:46:33" itemprop="dateCreated datePublished" datetime="2021-07-27T17:45:38+08:00">2021-07-27</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E8%BF%90%E7%BB%B4/" itemprop="url" rel="index"><span itemprop="name">运维</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h1 id="Docker"><a href="#Docker" class="headerlink" title="Docker"></a>Docker</h1><h2 id="1、安装"><a href="#1、安装" class="headerlink" title="1、安装"></a>1、安装</h2><p>配置安装源</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo</span><br></pre></td></tr></table></figure>

<p>查询docker版本信息</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum list docker-ce --showduplicates | sort -r</span><br></pre></td></tr></table></figure>

<p>安装docker</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install docker-ce-17.12.1.ce -y</span><br></pre></td></tr></table></figure>

<p>启动</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl start docker</span><br></pre></td></tr></table></figure>



<h2 id="2、配置"><a href="#2、配置" class="headerlink" title="2、配置"></a>2、配置</h2><p>1、配置国内源地址</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/docker/daemon.json</span><br><span class="line"></span><br><span class="line"># 添加如下信息</span><br><span class="line">&#123;</span><br><span class="line">  &quot;registry-mirrors&quot;: [</span><br><span class="line">    &quot;https://xx4bwyg2.mirror.aliyuncs.com&quot;,</span><br><span class="line">    &quot;http://f1361db2.m.daocloud.io&quot;,</span><br><span class="line">    &quot;https://registry.docker-cn.com&quot;,</span><br><span class="line">    &quot;http://hub-mirror.c.163.com&quot;,</span><br><span class="line">    &quot;https://docker.mirrors.ustc.edu.cn&quot;</span><br><span class="line">  ]</span><br><span class="line">&#125;&#123;&#125;</span><br></pre></td></tr></table></figure>

<p>加载配置</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl daemon-reload</span><br></pre></td></tr></table></figure>

<p>重启docker</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl restart docker</span><br></pre></td></tr></table></figure>

<p>2、修改镜像的默认存储路径</p>
<p>查看docker默认镜像路径</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker info</span><br></pre></td></tr></table></figure>

<p>修改默认镜像路径</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim /usr/lib/systemd/system/docker.serviceExecStart=/usr/bin/dockerd --graph=/data/docker </span><br></pre></td></tr></table></figure>

<p>迁移历史的镜像文件到新目录</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mv /var/lib/docker /data/docker </span><br></pre></td></tr></table></figure>



<p>加载重启</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl daemon-reloadsystemctl restart docker</span><br></pre></td></tr></table></figure>



<h2 id="3、镜像"><a href="#3、镜像" class="headerlink" title="3、镜像"></a>3、镜像</h2><p>查询镜像</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker search jboss</span><br></pre></td></tr></table></figure>

<p>下载镜像</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull jboss/wildfly</span><br></pre></td></tr></table></figure>

<p>查询镜像</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker images</span><br></pre></td></tr></table></figure>

<p>开通阿里云个人镜像仓库</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">1、登录阿里云2、容器服务---&gt;容器镜像服务----&gt;镜像列表---&gt;创建镜像仓库</span><br></pre></td></tr></table></figure>

<p>1、登录阿里云Docker Registry</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker login --username=128145****@qq.com registry.cn-hangzhou.aliyuncs.com</span><br></pre></td></tr></table></figure>

<p>2、从Registry中拉取镜像</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull registry.cn-hangzhou.aliyuncs.com/acho/docker:[镜像版本号]</span><br></pre></td></tr></table></figure>

<p>3、将镜像推送到Registry</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker login --username=128145****@qq.com registry.cn-hangzhou.aliyuncs.comdocker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/acho/docker:[镜像版本号]docker push registry.cn-hangzhou.aliyuncs.com/acho/docker:[镜像版本号]</span><br></pre></td></tr></table></figure>

<h2 id="4、定制镜像"><a href="#4、定制镜像" class="headerlink" title="4、定制镜像"></a>4、定制镜像</h2><p>1、理解docker的组成</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">仓库：存放镜像的地方镜像：原始的docker可执行文件容器：镜像启动之后的运行整体</span><br></pre></td></tr></table></figure>

<p>2、三者之间的转换关系</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">镜像-------run--------&gt;容器常用参数：-v:主机和容器的目录映射关系，&quot;:&quot;前为主机目录，之后为容器目录–name：容器名，此处命名为mysql-e：配置信息，此处配置mysql的root用户的登陆密码-p：端口映射，此处映射 主机3306端口:容器的3306端口-d：后台运行容器，保证在退出终端后容器继续运行-m :设置容器使用内存最大值；-ti:终端命令交互模式容器-------commit----&gt;镜像参数：-a:修改人-m:备注-c:使用DockerFile指令创建镜像-p:创建镜像时将容器暂停实例DockerFileFROM jboss/keycloakMAINTAINER td.achoEXPOSE 8080RUN sed -i &#x27;1i\JAVA_OPTS=&quot;-Xms2048m -Xmx2048m -XX:MetaspaceSize=200M -XX:MaxMetaspaceSize=1024m -Djava.net.preferIPv4Stack=true&quot;&#x27; /opt/jboss/keycloak/bin/standalone.confADD xx.war /opt/jboss/keycloak/standalone/deployments/</span><br></pre></td></tr></table></figure>

<p>3、mysql8.0 docker运行指令</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -p 3306:3306 --name mysql \-v /data/docker/mysql/conf:/etc/mysql \-v /data/docker/mysql/logs:/var/log/mysql \-v /data/docker/mysql/data:/var/lib/mysql \-v /data/docker/mysql-files:/var/lib/mysql-files/ \-e  MYSQL_ROOT_PASSWORD=tongda666 -d mysql </span><br></pre></td></tr></table></figure>

<p>4、修改配置</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysql8.0不支持：grant all privileges on *.* to root@&quot;%&quot; identified by &quot;.&quot;;先创建用户：CREATE USER &#x27;root&#x27;@&#x27;%&#x27; IDENTIFIED BY &#x27;tongda666&#x27;;再给用户授权：grant all privileges on *.* to &#x27;root&#x27;@&#x27;%&#x27; ;刷新授权flush privileges；在创建对应的数据库CREATE DATABASE IF NOT EXISTS `xx` CHARACTER SET utf8 COLLATE utf8_general_ci;</span><br></pre></td></tr></table></figure>

<p>5、启动redis</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -itd --name redis-test -p 6379:6379 redis</span><br></pre></td></tr></table></figure>

<p>6、启动activemq</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run --name=&#x27;activemq&#x27; \-itd \-p 8161:8161 \-p 61616:61616 \-e ACTIVEMQ_ADMIN_LOGIN=admin \-e ACTIVEMQ_ADMIN_PASSWORD=admin \--restart=always \-v /data/docker/activemq:/data/activemq \-v /data/docker/activemq/log:/var/log/activemq \webcenter/activemq</span><br></pre></td></tr></table></figure>

<p>7、启动nginx</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run --name nginx-test -p 8080:80 -d nginx</span><br></pre></td></tr></table></figure>

<p>8、显示所有容器IP地址</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker inspect --format=&#x27;&#123;&#123;.Name&#125;&#125; - &#123;&#123;range .NetworkSettings.Networks&#125;&#125;&#123;&#123;.IPAddress&#125;&#125;&#123;&#123;end&#125;&#125;&#x27; $(docker ps -aq)</span><br></pre></td></tr></table></figure>

<p>9、启动vsftpd</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">docker run -d -p 21:21 -p 20:20 \</span><br><span class="line">-p 3001-3100:3001-3100 \</span><br><span class="line">-v /home/docker/Ftpfile:/home/vsftpd \</span><br><span class="line">-e FTP_USER=busonline \</span><br><span class="line">-e FTP_PASS=busonline \</span><br><span class="line">-e PASV_ADDRESS=121.37.236.255 \</span><br><span class="line">-e PASV_MIN_PORT=3001 \</span><br><span class="line">-e PASV_MAX_PORT=3100 \</span><br><span class="line">--name vsftpd \</span><br><span class="line">--restart=always \</span><br><span class="line">fauria/vsftpd</span><br></pre></td></tr></table></figure>

<p>10、mysql5.7</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">docker run -p 3308:3306 \</span><br><span class="line">--name mysql5.7 \</span><br><span class="line">-v /data/docker/mysql5.7/conf:/etc/mysql/conf.d \</span><br><span class="line">-v /data/docker/mysql5.7/logs:/logs \</span><br><span class="line">-v /data/docker/mysql5.7/data:/var/lib/mysql \</span><br><span class="line">-e MYSQL_ROOT_PASSWORD=root \</span><br><span class="line">-d mysql:5.7</span><br></pre></td></tr></table></figure>



<h2 id="5、镜像层数"><a href="#5、镜像层数" class="headerlink" title="5、镜像层数"></a>5、镜像层数</h2><p>1、影响镜像层数的命令-RUN-COPY-ADD</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">RUN：RUN yum install wgetRUN wget -O redis.tar.gz &quot;http://download.redis.io/releases/redis-5.0.3.tar.gz&quot;RUN tar -xvf redis.tar.gz会创建三层镜像简化：RUN yum install wget \    &amp;&amp; wget -O redis.tar.gz &quot;http://download.redis.io/releases/redis-5.0.3.tar.gz&quot; \    &amp;&amp; tar -xvf redis.tar.gz创建一层镜像COPY:ADD:</span><br></pre></td></tr></table></figure>

<h2 id="6、DockerFile"><a href="#6、DockerFile" class="headerlink" title="6、DockerFile"></a>6、DockerFile</h2><p>1、实例打包jboss</p>
<figure class="highlight dockerfile"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">FROM</span> centos:centos7MAINTAINER TD_Acho<span class="comment">#拷贝文件COPY jboss-eap-6.1  /data/TDserver/jboss-eap-6.1COPY jdk1.7.0_80 /data/TDserver/jdk1.7.0_80COPY props /usr/local/Server/busonline/propsCOPY standalone.conf /data/TDserver/jboss-eap-6.1/bin/standalone.conf#设置环境变量ENV JAVA_HOME=/data/TDserver/jdk1.7.0_80ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$JAVA_HOME/bin#公开端口EXPOSE 8080WORKDIR /data/TDserver/jboss-eap-6.1/bin/RUN /usr/bin/chmod +x standalone.shENTRYPOINT [&quot;/usr/bin/sh&quot;,&quot;standalone.sh&quot;]</span></span><br></pre></td></tr></table></figure>

<p>2、屏蔽同级目录下的其余不相关文件</p>
<p>在DockerFile同级目录下新建 .dockerignore （前面有一个.）将需要屏蔽的文件放到这个文件中，build时就不会加载到docker daemon</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">jdk-7u80-linux-x64.tar.gz  props.zip        tdserver.tarjboss-eap-6.0.zip</span><br></pre></td></tr></table></figure>

<p>3、运行中的容器保存为镜像</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker commit -a &#x27;acho&#x27; -m &#x27;空的jboss容器&#x27; 4efc90e19586 jboss:v2-a : 修改人-m : 注解4efc90e19586 ： 容器IDjboss.v2： 生成的镜像名称</span><br></pre></td></tr></table></figure>






    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Docker/" rel="tag"># Docker</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2021/07/21/%E8%B7%A8%E5%9F%9F/" rel="prev" title="跨域">
                  <i class="fa fa-chevron-left"></i> 跨域
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2021/10/14/%E9%93%BE%E6%8E%A5%E5%88%86%E4%BA%AB%E6%B1%87%E6%80%BB/" rel="next" title="链接分享汇总">
                  链接分享汇总 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">acho ops</span>
</div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/pisces/" rel="noopener" target="_blank">NexT.Pisces</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>

  
<script src="/js/third-party/search/local-search.js"></script>




  
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





</body>
</html>
